﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using S5230WallpaperCreator.Properties;
using System.Threading;

namespace S5230WallpaperCreator
{

    /// <summary>
    /// 
    /// </summary>
    public partial class SelectLanguageForm : Form
    {

        /// <summary>
        /// Initializes a new instance of the <see cref="SelectLanguageForm"/> class.
        /// </summary>
        public SelectLanguageForm()
        {
            InitializeComponent();

            InitLanguageList();
        }

        /// <summary>
        /// Inits the language list.
        /// </summary>
        private void InitLanguageList()
        {
            //checkBoxShowAgain.Checked = Settings.Default.ShowChooseLanguage;

            comboBoxLanguageList.Items.Add(new LanguageDef(string.Format("{0}", Thread.CurrentThread.CurrentUICulture.DisplayName), ""));

            comboBoxLanguageList.Items.Add(new LanguageDef("English", "en"));
            comboBoxLanguageList.Items.Add(new LanguageDef("Русский", "ru"));
            comboBoxLanguageList.Items.Add(new LanguageDef("Português", "pt"));

            comboBoxLanguageList.SelectedIndex = 0;

            for (int index = 1; index < comboBoxLanguageList.Items.Count; index++)
            {
                LanguageDef def = (LanguageDef)comboBoxLanguageList.Items[index];

                if (Settings.Default.Localization.Equals(def.Locale, StringComparison.InvariantCultureIgnoreCase))
                {
                    comboBoxLanguageList.SelectedIndex = index;
                }
            }
        }

        /// <summary>
        /// Handles the Click event of the buttonOK control.
        /// </summary>
        /// <param name="sender">The source of the event.</param>
        /// <param name="e">The <see cref="System.EventArgs"/> instance containing the event data.</param>
        private void buttonOK_Click(object sender, EventArgs e)
        {
            Settings.Default.ShowChooseLanguage = checkBoxShowAgain.Checked;
            Settings.Default.Localization = ((LanguageDef)comboBoxLanguageList.SelectedItem).Locale;

            Settings.Default.Save();
        }
    }
}
